package com.hzcx.app.simplechat.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatTextView;

import com.hzcx.app.simplechat.R;


/**
 *  点赞按钮
 */
public class CommentTextView extends AppCompatTextView {

    private int commentNum=0;

    public CommentTextView(Context context) {
        super(context);
        init();
    }

    public CommentTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CommentTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        setFabulousNum(0);
    }

    /**
     *  设置点赞数
     * @param num
     */
    public void setFabulousNum(int num){
        this.commentNum=num;
        if(num>0){
            setText(num+"");
            setTextColor(getResources().getColor(R.color.color_ABADB5));
        }else {
            setText("评论");
            setTextColor(getResources().getColor(R.color.color_ABADB5));
        }
    }

    /**
     *  设置是否已经点赞过
     * @param comment
     */
    public void setIsComment(int comment){
        if(comment==1){
            Drawable drawableBoy = getResources().getDrawable(R.mipmap.ic_icon_comment_blue);
            drawableBoy.setBounds(0, 0, drawableBoy.getMinimumWidth(), drawableBoy.getMinimumHeight());
            setCompoundDrawables(drawableBoy, null, null, null);
        }else {
            Drawable drawableBoy = getResources().getDrawable(R.mipmap.ic_icon_comment_white);
            drawableBoy.setBounds(0, 0, drawableBoy.getMinimumWidth(), drawableBoy.getMinimumHeight());
            setCompoundDrawables(drawableBoy, null, null, null);
        }
    }

    /**
     *  获取点赞数
     * @return
     */
    public int getCommentNum(){
        return commentNum;
    }
}
